﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SWDataDB.Models;
using SWDataDB.BLL;
using SWDataDB.DAL;
using System.Data;

public partial class AdminManage_Edit_ZKEdit : System.Web.UI.Page
{
    public string zkid = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        zkid = Request["zkid"];
        bind();
    }


    private void bind()
    {
        YXInfo zkquery = new YXInfo();
        int ZKID = Convert.ToInt32(zkid);
        DataSet ds = zkquery.GetInfoByID(ZKID);
        DataRowView dv = ds.Tables[0].DefaultView[0];


        ZK_CODE.Text = Convert.ToString(dv.Row["ZK_CODE"]);
        KT_LCODE.Text = Convert.ToString(dv.Row["KT_LCODE"]);


        ZK_LONGITUDE_D.Text = Convert.ToString(dv.Row["ZK_LONGITUDE"]).Substring(0, 3);
        ZK_LONGITUDE_F.Text = Convert.ToString(dv.Row["ZK_LONGITUDE"]).Substring(3, 2);
        ZK_LONGITUDE_M.Text = Convert.ToString(dv.Row["ZK_LONGITUDE"]).Substring(5);
        ZK_LATITUDE_D.Text = Convert.ToString(dv.Row["ZK_LATITUDE"]).Substring(0, 2);
        ZK_LATITUDE_F.Text = Convert.ToString(dv.Row["ZK_LATITUDE"]).Substring(2, 2);

        ZK_LATITUDE_M.Text = Convert.ToString(dv.Row["ZK_LATITUDE"]).Substring(4);


        ZK_X.Text = Convert.ToString(dv.Row["ZK_X"]);
        ZK_Y.Text = Convert.ToString(dv.Row["ZK_Y"]);
        ZK_DEPTH.Text = Convert.ToString(dv.Row["ZK_DEPTH"]);
        ZK_CORELEN.Text = Convert.ToString(dv.Row["ZK_CORELEN"]);



        ZKYX_COUNT.Text = Convert.ToString(dv.Row["ZKYX_COUNT"]);
        GCYX_COUNT.Text = Convert.ToString(dv.Row["GCYX_COUNT"]);
        IMAGE.Text = Convert.ToString(dv.Row["IMAGE"]);//行政区划
        START_DATE.Text = Convert.ToString(dv.Row["START_DATE"]);
        END_DATE.Text = Convert.ToString(dv.Row["END_DATE"]);
        ZL_FILE_ID.Text = Convert.ToString(dv.Row["ZL_FILE_ID"]);


        //从著录表中读取title
        ZLInfo ZLFILEID = new ZLInfo();
        ZL_TBL zl = ZLFILEID.SelectZLInfoByID(dv.Row["ZL_FILE_ID"].ToString());
        TITLE_.Text = zl.O_TITLE;
        FileTitle.Text = zl.O_TITLE;
    }


    protected void submit_Click(object sender, EventArgs e)
    {
        YX_TBL yxobj = new YX_TBL();
        YXInfo kc_in = new YXInfo();

        yxobj.O_ZK_CODE = Request.Form["ZK_CODE"];
        yxobj.O_KT_LCODE = Request.Form["KT_LCODE"];


        yxobj.O_ZK_LONGITUDE = int.Parse((Request.Form["ZK_LONGITUDE_D"] + Request.Form["ZK_LONGITUDE_F"] + Request.Form["ZK_LONGITUDE_M"]));
        yxobj.O_ZK_LATITUDE = int.Parse((Request.Form["ZK_LATITUDE_D"] + Request.Form["ZK_LATITUDE_F"] + Request.Form["ZK_LATITUDE_M"]));


        yxobj.O_ZK_X = Request.Form["ZK_X"].Trim().Length == 0 ? 0 : float.Parse((Request.Form["ZK_X"]));  
        yxobj.O_ZK_Y = Request.Form["ZK_Y"].Trim().Length == 0 ? 0 : float.Parse((Request.Form["ZK_Y"])); 
        yxobj.O_ZK_H = Request.Form["ZK_H"].Trim().Length == 0 ? 0 : float.Parse((Request.Form["ZK_H"]));  

        yxobj.O_ZK_DEPTH = Request.Form["ZK_DEPTH"].Trim().Length == 0 ? 0 : float.Parse((Request.Form["ZK_DEPTH"]));  


        
        yxobj.O_ZK_CORELEN =Request.Form["ZK_CORELEN"].Trim().Length==0?0: float.Parse((Request.Form["ZK_CORELEN"]));
        yxobj.O_GC_CORELEN = Request.Form["GC_CORELEN"].Trim().Length ==0?0:float.Parse((Request.Form["GC_CORELEN"]));

        yxobj.O_ZKYX_COUNT = Request.Form["ZKYX_COUNT"].Trim().Length == 0?0:int.Parse((Request.Form["ZKYX_COUNT"]));
        yxobj.O_GCYX_COUNT = Request.Form["GCYX_COUNT"].Trim().Length == 0?0:int.Parse((Request.Form["GCYX_COUNT"]));
        //yxobj.O_IMAGE = float.Parse((Request.Form["IMAGE"];
        yxobj.O_START_DATE = Request.Form["START_DATE"];
        yxobj.O_END_DATE = Request.Form["END_DATE"];
        yxobj.O_ZL_FILE_ID = Request.Form["ZL_FILE_ID"];
        yxobj.O_ID = int.Parse(zkid);






        if (kc_in.UpdateYXInfo(yxobj) == 1)
        {
            bind();
            Response.Write("<script language=javascript>alert('更新成功！');location='../Manage/ZKManage.aspx'</script>");
            //Response.Redirect("ZLManage.aspx");
        }
        else
        {
            Response.Write("<script language=javascript>alert('更新失败！');location='../Manage/ZKManage.aspx'</script>");
        }
    }
}